﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace Novapangeia.Repositorio
{
    public class Auxiliar
    {
        /// <summary>
        /// Grava o arquivo de log, com os erros encontrados
        /// </summary>
        /// <param name="mensagem"></param>
        /// <param name="metodo"></param>
        /// <returns></returns>
        public static bool GravaLog(string mensagem, string metodo)
        {
            try
            {
                if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\logsite.txt"))
                {
                    StreamReader reader = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "\\logsite.txt");
                    string conteudo = reader.ReadToEnd();
                    reader.Close();

                    StreamWriter writer = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\logsite.txt");
                    writer.WriteLine(conteudo);
                    writer.WriteLine(DateTime.Now + " - Erro:" + mensagem + " - Ocorrido no " + metodo);
                    writer.Close();
                }
                else
                {
                    StreamWriter writer = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\logsite.txt");
                    writer.WriteLine(DateTime.Now + " - Erro:" + mensagem + " - Ocorrido no " + metodo);
                    writer.Close();
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}